package xyz.renyumeng.xkm.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import xyz.renyumeng.xkm.result.Result;

/**
 * @author renyumeng
 * @date Created in 21:24 2022/10/24
 */


@Slf4j
@ResponseBody
@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    public Result<Object> error(Exception e) {
        log.error(e.getMessage());
        return Result.fail().message("代码内部异常");
    }


    @ExceptionHandler(ArithmeticException.class)
    public Result<Object> error(ArithmeticException e) {
        log.error(e.getMessage());
        return Result.fail().message("特定异常处理");
    }


    @ExceptionHandler(XkmException.class)
    public Result<Object> error(XkmException e) {
        log.error(e.getMsg());
        return Result.fail().message(e.getMsg()).code(e.getCode());

    }
}
